<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>数据字典</title>
<script type="text/javascript">

//初始化checkbox
jQuery("document").ready(function(){
	
	 $.fn.zTree.init($("#treeDemo"), setting);
	
	jQuery("#all").click(function(){
			var flag = document.getElementById("all").checked;
	   	 	jQuery("[name=selId]:checkbox").each(function() {
	        		jQuery(this).attr("checked", flag);
	   		});
   });


$("#Pagination").paginate({
	count 		: '${count}',	//页数
	start 		: '${currentPageNo}',
	display     : 10,
	border					: true,
	border_color			: '#BEF8B8',
	text_color  			: '#68BA64',
	background_color    	: '#CAE8EA',	
	border_hover_color		: '#68BA64',
	text_hover_color  		: 'black',
	background_hover_color	: '#CAE8EA', 
	rotate      : false,
	images		: false,
	mouse		: 'press',
	onChange     			: function(page){	
		                          $("#currentPageNo").val(page);
			                      var url = ctx+'/ufmDict/findAll';
			                      document.form1.action=url;
			                      document.form1.submit();
							  }
});


	 if($.inArray("数据字典_删除", allRights)>=0){
		 $("#delete").show();
	 	   $("a[name='delete1']").show();
	 }
	 if($.inArray("数据字典_新增", allRights)>=0){
		 $("#add").show();
	 }
	 if($.inArray("数据字典_修改", allRights)>=0){
	 	   $("a[name='edit']").show();
	 }
	 if($.inArray("数据字典_查询", allRights)>=0){
	 	   $("#find").show();
	 }	
});
function addNew(){
	var id = jQuery('#dictId').val();	
	if(id != 0){
		var formObj = document.getElementById("form1");
		var url = ctx+'/ufmDict/isTop'; 
		 url += '?id='+id;	
		$.ajax({
		    url:url,
		    type: "GET",
		  //  dataType:"html",
		    cache : false,
		    async:false,
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				//	alert(XMLHttpRequest.readyState);
				},
				success: function(data) {				
		    	if(data == "false"){	
		    		alert("不能在本条数据下添加数据，因为本条数据已经停用!");
				}else if(data == "false2"){
					alert("不能添加数据，因为普通字典下面 不能继续添加子项目!");
				}else{					
					formObj.action=ctx+'/ufmDict/addDict';
					formObj.submit();
				} 		 
		    }
		});
	}else{
		alert("请先选择字典分类!");
	}
	
	
}

function search(dictId){	
	var formObj = document.getElementById("form1");
	$('#dictId').val(dictId);
	$("#currentPageNo").val(1);
	formObj.action=ctx+'/ufmDict/findAll';
	formObj.submit();
}

function lookDict(dictId){
	var formObj = document.getElementById("form1");
	$('#dictId').val(dictId);
	formObj.action=ctx+'/ufmDict/lookDict';
	formObj.submit();
}

function toUpdatePage(dictId){
	var formObj = document.getElementById("form1");
	$('#dictId').val(dictId);
	formObj.action=ctx+'/ufmDict/toUpdatePage';
	formObj.submit();
}


function deleteAll(value){
	var formObj = document.getElementById("form1");
	
	var chk_value =[];
	$('input[name="selId"]:checked').each(function(){    
			chk_value.push(jQuery(this).val());
	});
	var selIds = chk_value.join();
	if(selIds==''){
		alert("请选择要删除的记录!");
		return;
	}
	
	 if(confirm("是否确认要删除?")){
			
			var url = ctx+'/ufmDict/deleteAll'; 
			 url += '?selIds='+selIds;	   
			$.ajax({
			    url:url,
			    type: "GET",
			 //   dataType:"html",
			    cache : false,
			    async:false,
				error : function(XMLHttpRequest, textStatus, errorThrown) {
	   			//	alert(XMLHttpRequest.readyState);
	   			},
	   			success: function(data) {		   				
			    	if(data == "isUse"){	
			    		alert("不能删除该条数据，因为数据已经被使用!");
					}else if(data == "isChild"){	
			    		alert("不能删除该条数据，因为数据中有子节点!");
					}else{					
						formObj.action=ctx+'/ufmDict/findAll';
						formObj.submit();
					} 		 
			    }
			});
	 }
  } 

function deleteById(value){
	var formObj = document.getElementById("form1");
	
	 if(confirm("是否确认要删除?")){
		
			var url = ctx+'/ufmDict/deleteAll';
			   url += '?selIds='+value;	    
			$.ajax({
		    url:url,
		    type: "GET",
		 //   dataType:"html",
		    cache : false,
		    async:false,
			error : function(XMLHttpRequest, textStatus, errorThrown) {
   			//	alert(XMLHttpRequest.readyState);
   			},
   			success: function(data) {	   			
   				if(data == "isUse"){	
		    		alert("不能删除该条数据，因为数据已经被使用!");
				}else if(data == "isChild"){	
		    		alert("不能删除该条数据，因为数据中有子节点!");
				}else{		
					formObj.action=ctx+'/ufmDict/findAll';
					formObj.submit();
				} 		 
		    }
		});
	 }
  }



   
   // zTree
   var setting = {
			async: {
				enable: true,
				url:"${pageContext.request.contextPath}/ufmDict/getTree",
				autoParam:["z1", "level"]
			},
		   data: {		
			   simpleData: {
			          enable: true
		           }
	                 },
	     callback: {
		       onClick: zTreeOnClick
	           }

};
   // zTree 
   var zNodes = [
             <c:forEach items="${dictAll}" var="all" varStatus="i">           
                     {id:"${all.z1}", pId:"${all.z2}", name: "${all.z3}"},        
            </c:forEach>        

   ];

   
   function zTreeOnClick(event, treeId, treeNode) {
	
	     var d = treeNode.id;	    
	   $('#dictId').val(d);
	   var url1 = ctx+'/ufmDict/ajaxGetTree';
	    url1 += '?parentId='+d;
		 jQuery.ajax({
			    url:url1,
			    type: "POST",
			    async:false,
			    success: function(data) {			    	
			    	$("#resultList").empty();
       				$("#resultList").html(data);
			    }
			});
	   
	   
	   
	};




</script>
</head>

<body>
  <div id="menu" style="overflow: scroll;height: 64%;width:20%">
	<ul id="treeDemo" class="ztree"></ul>
  </div>
  <div id="content"  style="height:500px">		
	<div>
	<form id="form1" name="form1" action="" method="post">
	          名称:<input type="text" id="dictName" name="dictName" value="${dictName }" /> &nbsp;&nbsp;
	      <input id ="find" style="display: none" type="button" value="查询" onclick="search()"/>&nbsp;&nbsp;
	      <input id ="add" style="display: none" type="button"   value="新增" onclick="addNew()"/>&nbsp;&nbsp;	
	      <input id ="delete" style="display: none" type="button" value="删除" onclick="deleteAll()"/>&nbsp;&nbsp;
	      <input type="hidden" id="dictId" name="dictId" value="${dictId}"/>
	      <input type="hidden" id="currentPageNo" name="currentPageNo" value="${currentPageNo}"/>
	      <input type="hidden" id="perPageNumber" name="perPageNumber" value="${perPageNumber}"/>
	       </form>
     </div>   
<div id="resultList">
<table id="mytable" cellspacing="0" summary="The technical specifications of the Apple PowerMac G5 series">  
  <tr>
  	<th><input type="checkbox" id="all" name="all"/></th> 
    <th>序号</th> 
    <th>编号</th> 
    <th>名称</th>
    <th>简码</th>   
    <th>属性1</th>        
    <th>属性2</th>
    <th>顺序号</th>
    <th>停用</th>  
    <th>创建人</th>
    <th>创建时间</th>
    <th>操作</th> 
  </tr> 
  <c:forEach items="${dict}" var="d" varStatus="i">
  	<tr> 
  		<td align="center"><input type="checkbox" id="selId" name="selId" value="${d.z1}"/></td> 
	   	<td>${i.index+1}</td>
	   	<td>${d.z1}</td>
	   	<td>${d.z3}</td>
	   <!--   <td><a href="javascript:void(0)" onclick="lookDict('${d.z1}')" >${d.z3}</a></td> -->
	    <td>${d.p11}</td> 
	    <td>${d.z6}</td>	    
	    <td>${d.z7}</td> 
	    <td>${d.p12}</td>
	    <td>${d.z13==1?"是":"否"}</td>	    
	    <td>${d.p13}</td>
	    <td><fmt:formatDate value="${d.p14}" type="date" pattern="yyyy-MM-dd HH:mm:ss"/></td>	
	    <td><a name="delete1" style="display: none" href="javascript:void(0)" onclick = "deleteById(${d.z1})">删除</a>
	    	<a name="edit" style="display: none" href="javascript:void(0)" onclick="toUpdatePage('${d.z1}')">修改</a></td>
  	</tr> 
  </c:forEach>  
</table>
<div id="Pagination" ></div> 
</div>  
</div>
</body>
</html>
